package com.zj.core.ui

import android.content.Context
import android.graphics.Color
import android.support.constraint.ConstraintLayout
import android.view.Gravity
import android.view.View
import android.view.ViewManager
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.customcamera.widget.CameraContainer
import com.zj.core.R
import org.jetbrains.anko.*
import org.jetbrains.anko.constraint.layout.constraintLayout
import org.jetbrains.anko.custom.ankoView

class CameraActivityUi(groupView:LinearLayout):AnkoComponent<Context>{
    private val view:LinearLayout=groupView
    lateinit var camera_container:CameraContainer
    lateinit var camera_tv_light:TextView
    lateinit var camera_iv_take:ImageView
    lateinit var camera_iv_back:ImageView
    lateinit var camera_iv_picture:ImageView


    override fun createView(ui: AnkoContext<Context>): View= with(view){
        constraintLayout {
            lparams(width= matchParent,height= matchParent)

            camera_container=cameracontainer{
                id=R.id.camera_container
                layoutParams=LinearLayout.LayoutParams(matchParent, matchParent)
            }

            camera_tv_light=textView {
                id=R.id.camera_tv_light
                setCompoundDrawablesWithIntrinsicBounds(null,null,null,
                    context.resources.getDrawable(R.drawable.camera_light_selector))
                compoundDrawablePadding=dip(15)
                gravity=Gravity.CENTER_HORIZONTAL
                text="看不清？打开灯光"
                textColor=Color.WHITE
                textSize=sp(12).toFloat()
                visibility=View.GONE
            }.lparams(width= wrapContent,height = wrapContent){
                bottomMargin=dip(120)
                topToTop= ConstraintLayout.LayoutParams.PARENT_ID
                bottomToBottom=ConstraintLayout.LayoutParams.PARENT_ID
                leftToLeft=ConstraintLayout.LayoutParams.PARENT_ID
                rightToRight=ConstraintLayout.LayoutParams.PARENT_ID
            }

            camera_iv_take=imageView {
                id=R.id.camera_iv_take
                background=context.resources.getDrawable(R.drawable.camera_ic_take)
            }.lparams(width=dip(55),height=dip(55)){
                bottomToBottom=ConstraintLayout.LayoutParams.PARENT_ID
                leftToLeft=ConstraintLayout.LayoutParams.PARENT_ID
                rightToRight=ConstraintLayout.LayoutParams.PARENT_ID
                bottomMargin=dip(10)
            }

            camera_iv_back=imageView{
                id=R.id.camera_iv_back
                background=context.resources.getDrawable(R.drawable.camera_ic_back)
            }.lparams(width=dip(30),height=dip(30)){
                topMargin=dip(40)
                topToTop=ConstraintLayout.LayoutParams.PARENT_ID
            }

            camera_iv_picture=imageView{
                id=R.id.camera_iv_picture
                background=context.resources.getDrawable(R.drawable.camera_ic_picture)
            }.lparams(width=dip(30),height=dip(30)){
                topMargin=dip(40)
                rightMargin=dip(15)
                rightToRight=ConstraintLayout.LayoutParams.PARENT_ID
                topToTop=ConstraintLayout.LayoutParams.PARENT_ID
            }
        }
    }

    fun ViewManager.cameracontainer(theme: Int = 0) = cameracontainer(theme) {}
    inline fun ViewManager.cameracontainer(theme: Int = 0, init: CameraContainer.() -> Unit) : CameraContainer {
        return ankoView({ CameraContainer(it) }, theme, init)
    }
}